package org.example.springaop.proxy;


import net.sf.cglib.proxy.Enhancer;
import org.example.springaop.interceptor.CGLIBInterceptor;

import java.lang.reflect.Proxy;

public class DynamicMain {
    public static void main(String[] args) {
        HouseSubject target = new RealHouseSubject();
        // 创建一个代理类：通过代理类、被代理实现的接口、方法调用处理器来创建
        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
                new Class[]{HouseSubject.class},
                new JDKInvocationHander(target));
        proxy.rentHose();

        HouseSubject proxy2 = (HouseSubject) Enhancer.create(target.getClass(), new CGLIBInterceptor(target));
        proxy2.rentHose();
    }


}
